/* eslint-disable space-before-blocks */
export default function providers (L) {
  L.TileLayer.ChinaProvider = L.TileLayer.extend({
    initialize: function (type, options) {
      // (type, Object)
      var providers = L.TileLayer.ChinaProvider.providers;
      var parts = type.split('.');
      var providerName = parts[0];
      var mapName = parts[1];
      var mapType = parts[2];
      var url = providers[providerName][mapName][mapType];
      options.subdomains = providers[providerName].Subdomains;
      options.key = options.key || providers[providerName].key;
      L.TileLayer.prototype.initialize.call(this, url, options);
    }
  });
  L.TileLayer.ChinaProvider.providers = {
    TianDiTu: {
      Normal: {
        Map: 'https://t{s}.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk={key}',
        biaozhu: 'https://t{s}.tianditu.gov.cn/cva_w/wmts?Service=WMTS&Request=GetTile&Version=1.0.0&layer=cva&tilematrixset=w&Format=tiles&TileMatrix={z}&TileRow={y}&TileCol={x}&tk={key}',
        Annotion: 'https://t{s}.tianditu.gov.cn/cva_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk={key}'
      },
      Satellite: {
        Map: 'https://t{s}.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk={key}',
        //Annotion卫星注记地图
        Annotion: 'https://t{s}.tianditu.gov.cn/cia_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk={key}'
      },
      Terrain: {
        Map: 'https://t{s}.tianditu.gov.cn/ter_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=ter&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk={key}',
        Annotion: 'https://t{s}.tianditu.gov.cn/cta_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cta&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk={key}'
      },
      Subdomains: ['0', '1', '2', '3', '4', '5', '6', '7']
      //key: '174705aebfe31b79b3587279e211cb9a'
    },
    GaoDe: {
      Normal: {
        Map: 'http://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'
      },
      Font: {
        Map: 'https://wprd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'
      },
      Satellite: {
        Map: 'http://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
        Annotion: 'http://webst0{s}.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}'
      },
      Subdomains: ['1', '2', '3', '4']
    },
    Google: {
      Normal: {
        Map: 'http://www.google.cn/maps/vt?lyrs=m@189&gl=cn&x={x}&y={y}&z={z}'
      },
      Satellite: {
        Map: 'http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}'
      },
      Subdomains: []
    },
    Geoq: {
      Normal: {
        Map: 'http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer/tile/{z}/{y}/{x}',
        PurplishBlue: 'http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}',
        Gray: 'http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetGray/MapServer/tile/{z}/{y}/{x}',
        Warm: 'http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetWarm/MapServer/tile/{z}/{y}/{x}'
      },
      Theme: {
        Hydro: 'http://thematic.geoq.cn/arcgis/rest/services/ThematicMaps/WorldHydroMap/MapServer/tile/{z}/{y}/{x}'
      },
      Subdomains: []
    },
    OSM: {
      Normal: {
        Map: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png'
      },
      Subdomains: ['a', 'b', 'c']
    },
    BaiDu: {
      Normal: {
        Map: 'http://online{s}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles={ph/pl}&scaler=1&p=1'
      },
      Satellite: {
        Map: 'http://shangetu{s}.map.bdimg.com/it/u=x={x};y={y};z={z};v=009;type=sate&fm=46',
        Annotion: 'http://online{s}.map.bdimg.com/tile/?qt=tile&x={x}&y={y}&z={z}&styles={sh/sl}&v=020'
      },
      Subdomains: ['1', '2', '3', '4', '5', '6', '7', '8', '9']
    }
  };
  L.tileLayer.chinaProvider = function (type, options) {
    return new L.TileLayer.ChinaProvider(type, options);
  };
}